package com.Txunda.fxw.ui.fgt;

import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.Txunda.fxw.R;
import com.Txunda.fxw.base.utils.util.JSONUtils;
import com.Txunda.fxw.base.utils.util.L;
import com.Txunda.fxw.base.utils.util.MapUtils;
import com.Txunda.fxw.base.utils.util.StringUtils;
import com.Txunda.fxw.ui.activity.home.EvaluateAty;
import com.Txunda.fxw.ui.base.BaseAty;
import com.Txunda.fxw.ui.http.Company;
import com.Txunda.fxw.ui.toolkit.util.DensityUtil;
import com.Txunda.fxw.ui.toolkit.util.PreferenceUtil;
import com.Txunda.fxw.ui.widget.XCSlideView;
import com.Txunda.fxw.view.RoundedImageView;
import com.Txunda.fxw.view.dialog.AlertDialog;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.io.File;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * @author NineTailDemonFox
 */
public class WebAty extends BaseAty implements PlatformActionListener {
    private LocationManager locationManager;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {

            switch (msg.what) {
                case 1:
                    linear_top.setVisibility(View.VISIBLE);
                    linear_bottom.setVisibility(View.GONE);
                    ValueAnimator animator2 = ValueAnimator.ofFloat(0, mScreenHeight);
                    animator2.setTarget(linear_bottom);
                    animator2.setDuration(1000).start();
                    animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_bottom.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    };

    private double latitude = 0.0;
    private double longitude = 0.0;

    @SuppressLint("HandlerLeak")
    Handler handler2 = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    showToast("微博分享成功");
                    finish();
                    break;
                case 2:
                    showToast("成功分享给微信好友"); // 分享到微信
                    finish();
                    break;
                case 3:
                    showToast("朋友圈分享成功"); // 分享到微信朋友圈
                    finish();
                    break;
                case 4:
                    showToast("QQ空间分享成功");
                    finish();
                    break;
                case 5:
                    showToast("分享已取消");
                    break;
                case 6:
                    showToast("分享失败");
                    break;
                default:
                    break;
            }
        }
    };

    @BindView(R.id.wv_web)
    WebView wvWeb;
    private String url = "";
    private Company company;
    protected String history;
    private String class_id, com_id;
    private boolean isCollect;
    private String collect_id;
    private SharedPreferences.Editor edit;

    private XCSlideView mSlideViewRight;
    @ViewInject(R.id.icon_logo_1)
    private RoundedImageView icon_logo_1;
    @ViewInject(R.id.text_pingjia)
    TextView text_pingjia;
    private String phone;
    private SharedPreferences sp;
    Drawable img_collect;
    Drawable img_not_collect;

    private String count = "1";

    private LinearLayout linear_top, linear_bottom;

    private float mScreenHeight;
    private String pic;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_web;
    }

    @Override
    protected void initialized() {
        url = getIntent().getStringExtra("url");
        if (getIntent().getStringExtra("count") != null || !getIntent().getStringExtra("count").equals("null") || !getIntent().getStringExtra("count").equals("null")) {
            count = getIntent().getStringExtra("count");
        }
        phone = getIntent().getStringExtra("phone");
        class_id = getIntent().getStringExtra("class_id");
        com_id = getIntent().getStringExtra("com_id");

        if (count.equals("1")) {
            type = getIntent().getStringExtra("type") + class_id;
        } else {
            type = getIntent().getStringExtra("type") + com_id;
        }
        Log.d("zdl", "============类型================" + type);
        sp = getSharedPreferences("COLLECT", Activity.MODE_PRIVATE);
        edit = sp.edit();
        collect_id = sp.getString("history_collect", "");
        L.e("=====类型=====", type);
        company = new Company();
        int mScreenWidth = DensityUtil.getScreenWidthAndHeight(this)[0];
        mSlideViewRight = XCSlideView.create(this, XCSlideView.Positon.RIGHT);
        View menuViewRight = LayoutInflater.from(this).inflate(R.layout.layout_slide, null);
        mSlideViewRight.setMenuView(this, menuViewRight);
        mSlideViewRight.setMenuWidth(mScreenWidth * 3 / 9);
        LinearLayout linear_setting = menuViewRight.findViewById(R.id.linear_setting);
        LinearLayout linear_phone = menuViewRight.findViewById(R.id.linear_phone);
        final TextView tv_collect = menuViewRight.findViewById(R.id.tv_collect);
        LinearLayout linear_share = menuViewRight.findViewById(R.id.linear_share);//分享
        LinearLayout leave_linear = menuViewRight.findViewById(R.id.linear_leave);//评价
        LinearLayout linear_qq = menuViewRight.findViewById(R.id.linear_qq);//qq
        LinearLayout linear_weixin = menuViewRight.findViewById(R.id.linear_weixin);//微信
        LinearLayout linear_weibo = menuViewRight.findViewById(R.id.linear_weibo);//微博
        LinearLayout linear_friends = menuViewRight.findViewById(R.id.linear_friends);//微博
        img_collect = getResources().getDrawable(R.drawable.icon_yet_collect); // 收藏图标
        img_not_collect = getResources().getDrawable(R.drawable.icon_collect3); // 未收藏图标
        img_collect.setBounds(0, 0, img_collect.getMinimumWidth(), img_collect.getMinimumHeight());
        img_not_collect.setBounds(0, 0, img_not_collect.getMinimumWidth(), img_not_collect.getMinimumHeight());
        linear_top = menuViewRight.findViewById(R.id.linear_top);
        linear_bottom = menuViewRight.findViewById(R.id.linear_bottom);

        DisplayMetrics outMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
        mScreenHeight = outMetrics.heightPixels;

        if (collect_id.contains(com_id)) { // 未收藏
            tv_collect.setText("已收藏");
            tv_collect.setCompoundDrawables(null, img_collect, null, null);
        } else { // 已收藏
            tv_collect.setText("收藏");
            tv_collect.setCompoundDrawables(null, img_not_collect, null, null);

        }

        //收藏
        tv_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                collect_id = sp.getString("history_collect", "");
                isCollect = collect_id.contains(com_id);
                if (!isCollect) { // 未收藏
                    tv_collect.setText("已收藏");
                    tv_collect.setCompoundDrawables(null, img_collect, null, null);
                    // 保存商家id的值
                    history = sp.getString("history_collect", "");

                    if (StringUtils.isEmpty(history)) {
                        history = com_id;
                    } else {
                        history += "," + com_id;
                    }
                    edit.putString("history_collect", history);
                    edit.apply();
                } else { // 收藏
                    tv_collect.setText("收藏");
                    tv_collect.setCompoundDrawables(null, img_not_collect, null, null);
                    // 去掉商家id的值
                    history = sp.getString("history_collect", "");
                    if (history.contains(com_id + ",")) {
                        history = history.replace(com_id + ",", "");
                    } else if (history.contains("," + com_id)) {
                        history = history.replace("," + com_id, "");
                    } else if (history.contains(com_id)) {
                        history = history.replace(com_id, "");
                    }
                    edit.putString("history_collect", history);
                    edit.commit();
                }
            }
        });
        //打电话
        linear_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tel == null) {
                    return;
                }
                try {
                    new AlertDialog(WebAty.this).builder().setTitle("提示").setMsg("电话: " + tel)
                            .setPositiveButton("确认", new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(Intent.ACTION_CALL,
                                            Uri.parse("tel: " + tel));
                                    startActivity(intent);

                                }
                            }).setNegativeButton("取消", new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    }).show();

                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
            }
        });
        // 导航
        linear_setting.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                startActivity(SettingAty.class, null);
                //百度导航
                getBaiduMap();
                //定义起终点坐标（天安门和百度大厦）
//                LatLng startPoint = new LatLng(39.915291, 116.403857);
//                LatLng endPoint = new LatLng(40.056858, 116.308194);
//构建导航参数
//                NaviParaOption para = new NaviParaOption()
//                        .startPoint(startPoint)
//                        .endPoint(endPoint)
//                        .startName("天安门")
//                        .endName("百度大厦");
////调起百度地图
//                try {
//                    BaiduMapNavigation.openBaiduMapWalkNavi(para, this);
//                } catch (BaiduMapAppNotSupportNaviException e) {
//                    e.printStackTrace();
//                    //调起失败的处理
//                }


//                Intent intent = getPackageManager().getLaunchIntentForPackage("com.baidu.BaiduMap");
//                startActivity(intent);

            }
        });
        //评价
        leave_linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("type", type);
                startActivity(EvaluateAty.class, bundle);
            }
        });

        LinearLayout linear_share2 = menuViewRight.findViewById(R.id.linear_share2);

        //分享
        linear_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 向上走的动画
                if (linear_top.getVisibility() == View.VISIBLE) {

                    linear_top.setVisibility(View.GONE);
                    linear_bottom.setVisibility(View.VISIBLE);
                    ValueAnimator animator = ValueAnimator.ofFloat(mScreenHeight / 2, 0);
                    animator.setTarget(linear_bottom);
                    animator.setDuration(500).start();
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_bottom.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                }
            }
        });
        linear_share2.setOnClickListener(new View.OnClickListener() {
            private Timer timer;
            TimerTask timetask;

            @Override
            public void onClick(View v) {
                if (linear_top.getVisibility() == View.GONE) {
                    linear_top.setVisibility(View.VISIBLE);
                    linear_bottom.setVisibility(View.GONE);
                    float start = 0 - mScreenHeight;
                    ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
                    animator.setTarget(linear_top);
                    animator.setDuration(500).start();
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_top.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                    timer = new Timer();
                    timetask = new TimerTask() {

                        @Override
                        public void run() {
                            Message msg = new Message();
                            msg.what = 1;
                            handler.sendMessage(msg);
                        }
                    };
                    timer.schedule(timetask, 300);
                }
            }
        });
        //QQ分享
        linear_qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isQQClientAvailable()) {
                    Platform.ShareParams sp1 = new Platform.ShareParams();
                    sp1.setTitle("峰行网");// 分享标题
                    sp1.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp1.setTitleUrl(url); // 网友点进链接后，可以看到分享的详情
                    sp1.setSite("峰行网");
                    sp1.setSiteUrl(url);
                    sp1.setImagePath(pic);
                    // 3、非常重要：获取平台对象
                    Platform qzone = ShareSDK.getPlatform(QQ.NAME);
                    qzone.setPlatformActionListener(WebAty.this);
                    // 执行分享
                    qzone.share(sp1);
                } else {
                    showToast("请下载并安装QQ客户端");
                }
            }
        });
        //微信
        linear_weixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 判断是否安装微信
                if (isWeixinAvilible()) {
                    Platform.ShareParams sp_hy = new Platform.ShareParams();
                    sp_hy.setShareType(Platform.SHARE_WEBPAGE); // 非常重要：一定要设置分享属性
                    sp_hy.setTitle("峰行网"); // 分享标题
                    sp_hy.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp_hy.setUrl(url);
                    sp_hy.setImagePath(pic);
                    // sp_hy.setImageData(BitmapFactory.decodeResource(getResources(),
                    // R.drawable.ic_launcher));
                    // 3、非常重要：获取平台对象
                    Platform wechathy = ShareSDK.getPlatform(Wechat.NAME);
                    wechathy.setPlatformActionListener(WebAty.this); // 设置分享事件回调
                    // 执行分享
                    wechathy.share(sp_hy);
                } else {
                    showToast("请下载并安装微信客户端");
                }
            }
        });
        //微博
        linear_weibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                showTips(R.drawable.error, "敬请期待");
                if (isWeixinAvilible()) {
                    SinaWeibo.ShareParams sp = new SinaWeibo.ShareParams();
                    sp.setShareType(Platform.SHARE_TEXT); // 非常重要：一定要设置分享属性
                    sp.setTitle("峰行网"); // 分享标题
                    sp.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp.setUrl(url);
                    sp.setImagePath(pic);
                    // 3、非常重要：获取平台对象
                    Platform wechatMoments = ShareSDK.getPlatform(SinaWeibo.NAME);
                    wechatMoments.setPlatformActionListener(WebAty.this); // 设置分享事件回调
                    // 执行分享
                    wechatMoments.share(sp);


//                    SinaWeibo.ShareParams sp = new SinaWeibo.ShareParams();
//                    sp.setTitle("顺心拼车");
//                    sp.setText("分享来自顺芯拼车");
////                sp.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
//                    sp.setImageData( BitmapFactory.decodeResource(getResources(),
//                            R.drawable.ic_launcher));
////                String s = saveBitmap(me, decodeResource);
////                sp.setImagePath(s);
//                    sp.setUrl(url);
//                    sp.setShareType(Platform.SHARE_TEXT);
//                    Log.d("ShareSDK", sp.toMap().toString());
//                    Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
//                    // 设置分享事件回调（注：回调放在不能保证在主线程调用，不可以在里面直接处理UI操作）
//                    weibo.setPlatformActionListener(new PlatformActionListener() {
//                        @Override
//                        public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
//                            Log.d("ShareSDK", "onComplete ---->  分享成功");
//
//                        }
//
//                        @Override
//                        public void onError(Platform platform, int i, Throwable throwable) {
//                            Log.d("ShareSDK", "onError ---->  分享失败" + throwable.getStackTrace().toString());
//                            Log.d("ShareSDK", "onError ---->  分享失败" + throwable.getMessage());
//                            throwable.getMessage();
//                            throwable.printStackTrace();
//                        }
//
//                        @Override
//                        public void onCancel(Platform platform, int i) {
//                            Log.d("ShareSDK", "onCancel ---->  分享取消");
//                        }
//                    });
//                    // 执行图文分享
//                    weibo.share(sp);

                } else {
                    showToast("请下载并安装微博客户端");
                }

            }
        });
        //朋友圈
        linear_friends.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isWeixinAvilible()) {
                    Platform.ShareParams sp = new Platform.ShareParams();
                    sp.setShareType(Platform.SHARE_WEBPAGE); // 非常重要：一定要设置分享属性
                    sp.setTitle("峰行网"); // 分享标题
                    sp.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp.setUrl(url);
                    sp.setImagePath(pic);
                    // 3、非常重要：获取平台对象
                    Platform wechatMoments = ShareSDK.getPlatform(WechatMoments.NAME);
                    wechatMoments.setPlatformActionListener(WebAty.this); // 设置分享事件回调
                    // 执行分享
                    wechatMoments.share(sp);
                } else {
                    showToast("请下载并安装微信客户端");
                }
            }
        });
    }

    @Override
    @OnClick({R.id.aty_title_icon, R.id.icon_logo_1, R.id.text_pingjia})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.aty_title_icon:
                this.finish();
                break;
            case R.id.icon_logo_1:
                if (!mSlideViewRight.isShow()) {
                    mSlideViewRight.show();
                }
                break;
            case R.id.text_pingjia:
                Bundle bundle = new Bundle();
                bundle.putString("type", type);
                startActivity(EvaluateAty.class, bundle);
                break;
            default:
                break;
        }
    }

    @SuppressLint("Override")
    @Override
    protected void requestData() {
        String serviceName = Context.LOCATION_SERVICE;
        locationManager = (LocationManager) getSystemService(serviceName);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = locationManager.getBestProvider(criteria, true);

        Location location = locationManager.getLastKnownLocation(provider);
        updateWithNewLocation(location);
        locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);


        WebSettings webSettings = wvWeb.getSettings();
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);// 设置缓存
        webSettings.setJavaScriptEnabled(true);//设置能够解析Javascript
        webSettings.setDomStorageEnabled(true);//设置适应Html5 //重点是这个设置
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        wvWeb.getSettings().getLoadsImagesAutomatically();


        wvWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口，如window.open()，默认为false
        wvWeb.getSettings().setSupportZoom(true);//是否可以缩放，默认true
        wvWeb.getSettings().setBuiltInZoomControls(true);//是否显示缩放按钮，默认false
        wvWeb.getSettings().setAppCacheEnabled(true);//是否使用缓存


        if (Build.VERSION.SDK_INT >= 21) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        wvWeb.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return super.shouldOverrideUrlLoading(view, url);
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed();
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // TODO Auto-generated method stub
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });
        wvWeb.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return false;
            }
        });
        //加载assets文件夹下的html
        wvWeb.loadUrl(url);
        String logo = PreferenceUtil.readString(this, PreferenceUtil.sp_logo);
        Glide.with(this).load(logo).into(icon_logo_1);
        company.companyDetail(com_id, class_id, this);
    }

    private final LocationListener locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            updateWithNewLocation(location);
        }

        @Override
        public void onProviderDisabled(String provider) {
            updateWithNewLocation(null);
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    };
    private void updateWithNewLocation(Location location) {
        if (location != null) {
            latitude = location.getLatitude();
            longitude = location.getLongitude();

//            Geocoder geocoder = new Geocoder(this);
//            List places = null;
//
//            try {
//                places = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 5);
//                Toast.makeText(WebAty.this, places.size() + "", Toast.LENGTH_LONG).show();
//                System.out.println(places.size() + "");
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//            String placename = "";
//            if (places != null && places.size() > 0) {
//                placename = ((Address) places.get(0)).getAddressLine(0) + ", " + System.getProperty("line.separator")
//                        + ((Address) places.get(0)).getAddressLine(1) + ", "
//                        + ((Address) places.get(0)).getAddressLine(2);
//            }
//            latitude = lat;
//            longitude = lng;
//            latLongString = "纬度:" + lat + "/n经度:" + lng;
        } else {
            Toast.makeText(this, "请打开定位", Toast.LENGTH_SHORT).show();
        }
//        button.setText("您当、前的位置是:/n" + latLongString);
    }


    private String tel;
    private String lat, lnt;

    @SuppressLint("SetTextI18n")
    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
        Log.d("zdl", "=========数据===========" + jsonStr);
        if (MapUtils.isEmpty(map)) {
            return;
        }
        if (requestUrl.contains("companyDetail")) { // 商家详情
            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
            if (MapUtils.isEmpty(data)) {
                return;
            }
            //获取商家经纬度
            lat = data.get("lat"); // 纬度
            lnt = data.get("lnt"); // 经度
            tel = data.get("tel"); // 商家电话
            pic = data.get("pic");
        }
    }

    @Override
    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        if (platform.getName().equals(SinaWeibo.NAME)) {// 判断成功的平台是不是新浪微博
            handler2.sendEmptyMessage(1); // 分享到微博
        } else if (platform.getName().equals(Wechat.NAME)) {
            handler2.sendEmptyMessage(2); // 分享给微信好友
        } else if (platform.getName().equals(WechatMoments.NAME)) {
            handler2.sendEmptyMessage(3); // 分享到微信朋友圈
        }
//        else if (platform.getName().equals(QZone.NAME)) {
//            handler2.sendEmptyMessage(4); // 分享到qq空间
//        }
    }

    @Override
    public void onError(Platform platform, int i, Throwable throwable) {
        throwable.printStackTrace();
        Message msg = new Message();
        msg.what = 6;
        msg.obj = throwable.getMessage();
        handler2.sendMessage(msg);
    }

    @Override
    public void onCancel(Platform platform, int i) {
        handler2.sendEmptyMessage(5); // 取消分享
    }

    //=========================================================
    private boolean isInstallByread(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }

    //判断百度地图
    private void getBaiduMap() {


        Log.d("zdl", "==========latitude==========" + latitude);
        Log.d("zdl", "===========longitude=========" + longitude);
        Log.d("zdl", "==========lat==========" + lat);
        Log.d("zdl", "==========lnt==========" + lnt);

        //RealTimeMonitorResultModel realTimeMonitorResultModel = FindCarMapManager.getRealTimeMonitorResultModel();
        try {

            if (isInstallByread("com.baidu.BaiduMap")) {

                Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:" + latitude + "," + longitude + "|name:起点&destination=" + lat + "," + lnt + "&mode=drivingion=终点&referer=Autohome|GasStation#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
                startActivity(intent); //启动调用
                Log.e("GasStation", "百度地图客户端已经安装");
            } else {
                showToast("请安装百度地图客户端");
            }
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

}
